package storm;
// @Author   :陈彤
import bean.order;
import bean.ordertail;
import org.apache.storm.task.OutputCollector;
import org.apache.storm.task.TopologyContext;
import org.apache.storm.topology.OutputFieldsDeclarer;
import org.apache.storm.topology.base.BaseRichBolt;
import org.apache.storm.tuple.Fields;
import org.apache.storm.tuple.Tuple;
import org.apache.storm.tuple.Values;

import java.util.HashMap;
import java.util.Map;


public class LogFileBolt2 extends BaseRichBolt {
    private OutputCollector collector;
    public static JRedisUtil jedis = new JRedisUtil("192.168.52.140",6379);//127.0.0.1
    public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
        this.collector = collector;
    }

    public void execute(Tuple tuple) {
        ordertail orderdetail = new ordertail();
        String detailInfo = (String) tuple.getValue(0);
        //System.out.println(detailInfo);
        orderdetail = spliteFile2.getOrdersBean(detailInfo);
//            System.out.println("---------2----------");
//            System.out.println(orderdetail.getSendplace().substring(0,2));
//            System.out.println("--------------------");
       // JRedisUtil jedis = new JRedisUtil("127.0.0.1",6379);
        try {
            Map<String, Double> myMap = new HashMap<String, Double>();
            myMap.put(orderdetail.getSendplace(),orderdetail.getFreight());
            //运费和地区的关系
            //jedis.zadd("Freight",myMap);
            //总金额
            jedis.incrBy("TotalPrice", (long) orderdetail.getTotal());
            // 下单客户数
            jedis.zincrby("CustomNum",1,orderdetail.getRecipient());
            // 各省份下单地区
            String place = orderdetail.getSendplace();
            //System.out.println(place.substring(0,4));
            if(place.substring(0,3).equals("黑龙江")||place.substring(0,3).equals("内蒙古")){
                jedis.zincrby("CMap",1,place.substring(0,3));
            }else {
                jedis.zincrby("CMap", 1, place.substring(0,2));
            }
            jedis.zincrby("PayWay",1,orderdetail.getMethodofpayment());
        }catch (Exception e){
            System.out.println(detailInfo);
            e.printStackTrace();
        }finally {
//            System.out.println("---------2----------");
//            System.out.println(orderdetail.getSender());
//            //System.out.println(jedis.get("total"));
//            System.out.println("--------------------");
        }

    }

    public void declareOutputFields(OutputFieldsDeclarer declarer) {
       // declarer.declare(new Fields(new String[]{"orderdetail"}));
    }
}